package com.example.online_exam_system.logic.impl;

import com.example.online_exam_system.dto.QuestionsDto;
import com.example.online_exam_system.logic.IQuestionsInfoService;
import com.example.online_exam_system.service.SubjectService;
import com.example.online_exam_system.service.TestQuestionsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description 试题相关业务逻辑
 * @Author lianglong
 * @Since 2021/12/1 0:58
 **/
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class QuestionsInfoServiceImpl implements IQuestionsInfoService {

	@Autowired
	TestQuestionsService testQuestionsService;

	@Autowired
	SubjectService subjectService;

	@Override
	public List<QuestionsDto> getQuestionsTable(String teacherId){
		List<QuestionsDto> questionsByTeacherId = testQuestionsService.getQuestionsByTeacherId();
		return questionsByTeacherId;
	}

	@Override
	public int insertQuestion(QuestionsDto questionsDto){
		return testQuestionsService.insertQuestion(questionsDto);
	}

	@Override
	public QuestionsDto addSubjectName(QuestionsDto questionsDto){
		//根据科目名字查找科目id
		String subjectName = questionsDto.getSubjectname();
		String subjectId = subjectService.querysubjectIdByName(subjectName);
		questionsDto.setSubjectid(subjectId);
		return questionsDto;
	}

}
